package com.example.attendancesystem.Mapper;


import com.example.attendancesystem.Models.News;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface NewsMapper {

    /**
     * 员工主页查询前三条新闻通知
     *
     * @return news列表
     */
    @Select("select id,title,author,release_time,img_path,content from news order by id desc limit 0,3")
    List<News> getNewsLimit();

    /**
     * 按标题模糊查询所有新闻信息
     * @param title 标题
     * @return List<News>
     */
    @Select("select id,title,author,release_time,img_path,content from news where title LIKE #{title} order by id desc")
    List<News> getAllNews(@Param("title") String title);


    /**
     * 按Id查找新闻
     * @param newsId id
     * @return News
     */
    @Select("select id,title,author,release_time,img_path,content from news where id = #{newsId}")
    News getNewsById(@Param("newsId") Integer newsId);


    /**
     * 插入一条新闻
     * @param title 标题
     * @param author 作者
     * @param text 内容
     * @param nowTime 发布时间
     * @return 操作受影响的记录数
     */
    @Insert("insert into news (title,author,release_time,img_path,content) " +
            "values ( #{title}, #{author},#{nowTime},'news1.jpg',#{text})")
    int addNews(@Param("title") String title, @Param("author") String author, @Param("text") String text,@Param("nowTime") String nowTime);


    /**
     * 更新新闻图片
     * @param newsId id
     * @param savaImgName 新图片名称
     */
    @Update("update news set img_path = #{savaImgName} where id = #{newsId} ")
    void updateEmpImg(@Param("newsId") Integer newsId,@Param("savaImgName") String savaImgName);
}
